﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace VNet.VisiSuite.Controls
{
    public partial class BottomSlidePanel
    {
        public delegate void OnClosePanel();

        private OnClosePanel _onClosePanel;

        public BottomSlidePanel()
        {
            InitializeComponent();
            _bottomPanel.DataContext = this;
        }

        public void SetIcons(IList<VNetMenuItem> menuItems)
        {
            _bottomMenu.Icons = menuItems;
        }

        public void UserControl(UIElement control)
        {
            _userControls.Children.Clear();
            if (control != null)
                _userControls.Children.Add(control);
        }

        public void OnCloseCallback(OnClosePanel callback)
        {
            _onClosePanel = callback;
        }

        public bool Contains(double parent_height, double ycoord)
        {
            return (ycoord < parent_height - _bottomPanel.ActualHeight + _bottomPanelTranslate.Y) ? false : true;
        }

        public void Show()
        {
            if (_bottomMenu.Count() > 0 || _userControls.Children.Count > 0)
            {
                var duration = new Duration(new TimeSpan(0, 0, 0, 0, 300));
                var anim = new DoubleAnimation(0, duration);
                _bottomPanelTranslate.BeginAnimation(TranslateTransform.YProperty, anim);
            }
        }

        public void Hide()
        {
            if (_bottomPanelTranslate.Y == 0.0)
            {
                double hh = _bottomPanel.ActualHeight;
                var duration = new Duration(new TimeSpan(0, 0, 0, 0, 150));
                var anim = new DoubleAnimation(hh, duration);
                _bottomPanelTranslate.BeginAnimation(TranslateTransform.YProperty, anim);
            }
        }

        public bool IsHidden()
        {
            double hh = _bottomPanel.ActualHeight;
            return _bottomPanelTranslate.Y == hh;
        }
    }
}